cmake_minimum_required(VERSION 3.8)
project(virtual_camera)

# C++ 17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# find dependencies
# ROS
find_package(ament_cmake REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)

# ROS Component
find_package(rclcpp_components REQUIRED)

# Third Party
find_package(OpenCV REQUIRED)
find_package(yaml-cpp REQUIRED)

add_library(camera_node SHARED
  src/camera_node.cpp
)

target_include_directories(camera_node PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>)
target_compile_features(camera_node PUBLIC c_std_99 cxx_std_17)  # Require C99 and C++17
ament_target_dependencies(
  camera_node
  "ament_index_cpp"
  "cv_bridge"
  "rclcpp"
  "rclcpp_components"
  "sensor_msgs"
)

target_link_libraries(camera_node
  ${OpenCV_LIBS}
  yaml-cpp
)

# ROS Component
rclcpp_components_register_node(
  camera_node
  PLUGIN "virtual_camera::CameraNode"
  EXECUTABLE virtual_camera
)

ament_export_targets(export_camera_node)
install(TARGETS camera_node
  EXPORT export_camera_node
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)

# install config
install(DIRECTORY config
  DESTINATION share/${PROJECT_NAME}
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
